/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import bean.Candidato;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import negocio.NegocioCandidato;

/**
 *
 * @author jcrbsa
 */
public class TerminateSessionCadastro extends HttpServlet {


  @Override
   
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
         HttpServletRequest req = (HttpServletRequest) request;
        NegocioCandidato fachada = NegocioCandidato.getInstance();
        HttpSession session = req.getSession(true);
        Candidato candidato = new Candidato();
        String cpf = req.getParameter("cpf2");
        candidato.setCpf(cpf);
        
        String status = (String)session.getAttribute("status");
          
                                        
        
        if (status != null) {
            
            
            if (fachada.procuraCPF(candidato) == true) {
                        
                    System.out.println("Já existe Candidato  - continua na mesma pagina");
                    req.getRequestDispatcher("/continuacacadastro.jsp").forward(request, response);

                }
            } 
        
            if (fachada.procuraCPF(candidato) == false) {
                   session.removeAttribute("status");
                   System.out.println("Não existe candidato - 'index'");
                  req.getRequestDispatcher("/index.jsp").forward(request, response);

                
            }
            
        }
    

  
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
